// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import 'babel-polyfill';
import Utils from '@/utils/index';
import App from './App';
import store from './store';
import router from './router';
import filters from './utils/filters';
import util from './utils/util';
import http from './utils/fetch';
import Vant from 'vant';
import axios from 'axios';

import 'vant/lib/index.css';

import './utils/px2rem';
// 自定义组件
let components = {
  inviteBtn: resolve => require.ensure([], () => resolve(require('@/base/invitebtn'))),
  glPicker: resolve => require.ensure([], () => resolve(require('@/base/glpicker'))),
  vipTip: resolve => require.ensure([], () => resolve(require('@/base/viptip'))),
  DetailTip: resolve => require.ensure([], () => resolve(require('@/base/detailtip'))),
  discountCard: resolve => require.ensure([], () => resolve(require('@/base/discountcard'))),
  GlPlayVideo: resolve => require.ensure([], () => resolve(require('@/base/playvideo'))),
  ScrollText: resolve => require.ensure([], () => resolve(require('@/base/scrolltext'))),
  CourseCard: resolve => require.ensure([], () => resolve(require('@/base/coursecard')))
};

Object.keys(components).map(k => {
  Vue.component(k, components[k]);
});

require('./less/component-style.less');

// 实例化Vue的filter
Object.keys(filters).forEach(k => Vue.filter(k, filters[k]));

Vue.use(Utils);
Vue.use(Vant);


Vue.prototype.$utils = Utils;
Vue.config.productionTip = false;
Vue.prototype.util = util;
Vue.prototype.http = http;

/* eslint-disable no-new */
(async () => {
  let currHtml = await axios.get('');
  let serverHtml = [...document.scripts].map(e => e.src).join('>');
  let curr = /app\.[^>]*\.js/i.exec(currHtml.data);
  let server = /app\.[^>]*\.js/i.exec(serverHtml);
  if (curr && server && curr[0] !== server[0]) return location.reload(true);
  new Vue({
    el: '#app',
    router,
    store,
    components: { App },
    template: '<App/>'
  });
})();
